#include "ProviderConnectorEnd.h"

#include "core/AppSignals.h"

ProviderConnectorEnd::ProviderConnectorEnd()
    : PropertyProvider()
{
}

void ProviderConnectorEnd::initEditor(
    QtTreePropertyBrowser* editor,
    shared_ptr<BaseElement> entity
)
{
    entity_ = dynamic_pointer_cast<uml::ConnectorEnd>(entity);
    propertyToId.clear();
    PropertyProvider::initEditor(editor, entity);

    addProperty("isOrdered", "isOrdered", entity_->isOrdered());
    addProperty("isUnique", "isUnique", entity_->isUnique());
    addProperty("lower", "lower", entity_->lower());
    addProperty("upper", "upper", entity_->upper());

}

void ProviderConnectorEnd::valueChanged(QtProperty* property, bool value)
{
    QString id = propertyToId[property];
    if (id == "isOrdered") {
        entity_->setIsOrdered(value);
        emit appSignals->onElementChanged(this, entity_);
    } else if (id == "isUnique") {
        entity_->setIsUnique(value);
        emit appSignals->onElementChanged(this, entity_);
    }
}

void ProviderConnectorEnd::valueChanged(QtProperty* property, double value)
{
    QString id = propertyToId[property];
    
}

void ProviderConnectorEnd::valueChanged(QtProperty* property, int value)
{
    QString id = propertyToId[property];
    if (id == "lower") {
        entity_->setLower(value);
        emit appSignals->onElementChanged(this, entity_);
    } else if (id == "upper") {
        entity_->setUpper(value);
        emit appSignals->onElementChanged(this, entity_);
    }
}

void ProviderConnectorEnd::valueChanged(QtProperty* property, QString value)
{
    QString id = propertyToId[property];
    
}
